package com.cskaoyan.controller;

import com.cskaoyan.bean.*;
import com.cskaoyan.bean.basebean.BaseRespVo;

import com.cskaoyan.service.BrandService;
import com.cskaoyan.service.RegionService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @description: ${description}
 * @author: cuicui
 **/

@RestController
public class MarketController {

    @Autowired
    RegionService regionService;

    @Autowired
    BrandService BrandService;

    @RequestMapping("admin/region/list")
    public BaseRespVo regionList() {
        DataDTO dataDTO = regionService.regionList();
        return BaseRespVo.ok(dataDTO);
    }

    @RequestMapping("admin/brand/list")
    public BaseRespVo brandList(BrandListBO bo) {
        BrandVO brandVO = BrandService.brandList(bo);
        return BaseRespVo.ok(brandVO);
    }

    @PostMapping("admin/brand/create")
    public BaseRespVo creatBrand(@RequestBody BrandCreateBO bo) {
        //参数判空
        if (StringUtils.isEmpty(bo.getDesc()) || StringUtils.isEmpty(bo.getFloorPrice())
                || StringUtils.isEmpty(bo.getPicUrl()) || StringUtils.isEmpty(bo.getName())) {
            return BaseRespVo.fail401("参数不能为空");
        }
        Brand brand = BrandService.creat(bo);
        return BaseRespVo.ok(brand);
    }

    @PostMapping("admin/brand/update")
    public BaseRespVo updateBrand(@RequestBody Brand brand) {
        //参数判空
        if (brand.getFloorPrice() == null || StringUtils.isEmpty(brand.getDesc()) || StringUtils.isEmpty(brand.getPicUrl()) || StringUtils.isEmpty(brand.getName())) {
            return BaseRespVo.fail401("参数不能为空");
        }
        Brand brandNew = BrandService.update(brand);
        return BaseRespVo.ok(brandNew);
    }

    @PostMapping("admin/brand/delete")
    public BaseRespVo delectBrand(@RequestBody Brand brand) {
        //逻辑删除
        BrandService.delectLogic(brand);
        return BaseRespVo.ok("成功");
    }

}
